home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / FWString / Include / FWStrToo.h < prev   
Encoding:
C/C++ Source or Header  |  1994-04-21  |  9.6 KB  |  275 lines  |  [TEXT/MPS ]

  1. #ifndef FWSTRTOO_H
  2. #define FWSTRTOO_H
  3. //========================================================================================
  4. //
  5. //    File:                FWStrToo.h
  6. //    Release Version:    $ 1.0d1 $
  7. //
  8. //    Creation Date:        3/28/94
  9. //
  10. //    Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  11. //
  12. //========================================================================================
  13.  
  14. #ifndef FWEXCDEF_H
  15. #include "FWExcDef.h"
  16. #endif
  17.  
  18. #ifndef FWSTRS_H
  19. #include "FWStrs.h"
  20. #endif
  21.  
  22. //========================================================================================
  23. //    CLASS FW_CStringTool
  24. //
  25. //        A tool for string operations.  StringTools are used for operations that don't fit
  26. //        well as methods of strings.  The principle reason for placing an operation in a 
  27. //        tool instead of a string is when the operation may have multiple algorithm 
  28. //        implementations.  We make this distinction because it is undesirable to force
  29. //        a user to subclass one or more string classes just to use a different set of
  30. //        tool algorithms.
  31. //
  32. //        Note that "StringTool" is only one kind of "string tool".  Other string tools
  33. //        include translation tools, format tools, etc.  This StringTool class is intended
  34. //        for "pure string" manipulation, e.g. searching and comparing.
  35. //
  36. //        The FW_CStringTool class is an abstract base class.
  37. //========================================================================================
  38.  
  39. enum FW_StringCompareResult
  40. {
  41.     kStringOneLess = -1, kStringsEqual = 0, kStringOneGreater = 1
  42. } ;
  43.  
  44. // Note: The following enumeration should be class scoped, but Borland croaks later
  45. // on if this is class scoped.
  46.  
  47. enum FW_FindDirection { FW_kForwards, FW_kBackwards };
  48.  
  49. class FW_CStringTool : public _FW_CAutoDestructObject
  50. {
  51. public:
  52.  
  53.     virtual ~FW_CStringTool();
  54.     FW_CStringTool(FW_Boolean caseSensitive=TRUE);
  55.     
  56.     FW_Boolean SetCaseSensitivity(FW_Boolean caseSensitive);
  57.         // Sets the sensitivity, returns prior sensitivity
  58.  
  59.     FW_StringCompareResult CompareStrings(FW_CTextReader &reader1,
  60.                                           FW_CTextReader &reader2);
  61.                                          
  62.     FW_StringCompareResult CompareStrings(const FW_CString &string1,
  63.                                           const FW_CString &string2);
  64.     
  65.     FW_Boolean FindSubString(FW_CTextReader &reader,
  66.                                      const FW_CString &subString,
  67.                                      FW_CharacterPosition &foundPosition);
  68.                                      
  69.     FW_Boolean FindSubString(const FW_CString &string,
  70.                             const FW_CString &subString,
  71.                             FW_CharacterPosition &foundPosition,
  72.                             FW_CharacterPosition startPosition=0);
  73.                                      
  74.     FW_Boolean FindCharacter(FW_CTextReader &reader,
  75.                                     FW_Char character,
  76.                                     FW_CharacterPosition &foundPosition,
  77.                                     FW_FindDirection direction=FW_kForwards);
  78.                                  
  79.     FW_Boolean FindCharacter(const FW_CString &string,
  80.                             FW_Char character,
  81.                             FW_CharacterPosition &foundPosition,
  82.                             FW_CharacterPosition startPosition=0,
  83.                             FW_FindDirection direction=FW_kForwards);
  84.                                     
  85.     FW_Boolean IsWhiteSpace(FW_Char character);
  86.                                  
  87.     FW_Boolean IsWhiteSpace(FW_CTextReader &reader);
  88.                                  
  89.     FW_Boolean FindWhiteSpace(FW_CTextReader &reader,
  90.                                         FW_CharacterPosition &foundPosition,
  91.                                         FW_FindDirection direction=FW_kForwards);
  92.                                  
  93.     FW_Boolean FindWhiteSpace(const FW_CString &string,
  94.                             FW_CharacterPosition &foundPosition,
  95.                             FW_CharacterPosition startPosition=0,
  96.                             FW_FindDirection direction=FW_kForwards);
  97.                                          
  98.     FW_Boolean FindNonWhiteSpace(FW_CTextReader &reader,
  99.                                         FW_CharacterPosition &foundPosition,
  100.                                         FW_FindDirection direction=FW_kForwards);
  101.  
  102.     FW_Boolean FindNonWhiteSpace(const FW_CString &string,
  103.                             FW_CharacterPosition &foundPosition,
  104.                             FW_CharacterPosition startPosition=0,
  105.                             FW_FindDirection direction=FW_kForwards);
  106.                                          
  107.     FW_Boolean Substitute(FW_CString &string,
  108.                     const FW_CString &searchString,
  109.                     const FW_CString &substitutionString);
  110.     
  111.     void ToUpper(FW_CTextReader &input, FW_CTextWriter &output);
  112.     
  113.     void ToUpper(FW_CString &string);
  114.     
  115.     void ToLower(FW_CTextReader &input, FW_CTextWriter &output);
  116.  
  117.     void ToLower(FW_CString &string);
  118.                                      
  119.     // ----- Static functions for accessing default and current string tools.
  120.  
  121.     static FW_CStringTool* GetCurrentStringTool();
  122.         // Return a pointer to the current string tool.
  123.         
  124.     static FW_CStringTool* SetCurrentStringTool(FW_CStringTool* tool);
  125.         // Make tool the current string tool.
  126.         // Returns the prior string tool.
  127.  
  128. protected:
  129.     
  130.     virtual FW_StringCompareResult DoCompareStrings(FW_CTextReader &reader1,
  131.                                           FW_CTextReader &reader2) = 0;
  132.                                          
  133.     virtual FW_Boolean DoMatchPrefixString(FW_CTextReader &target,
  134.                                           FW_CTextReader &prefix) = 0;
  135.                                          
  136.     virtual FW_Boolean DoFindSubString(FW_CTextReader &searchStringReader,
  137.                                      FW_CTextReader &subStringReader,
  138.                                      FW_CharacterPosition &foundPosition) = 0;
  139.                                      
  140.     virtual FW_Boolean DoFindCharacter(FW_CTextReader &reader,
  141.                                     FW_Char character,
  142.                                     FW_CharacterPosition &foundPosition,
  143.                                     FW_FindDirection direction=FW_kForwards) = 0;
  144.                                  
  145.     virtual FW_Boolean DoFindWhiteSpace(FW_CTextReader &reader,
  146.                                         FW_CharacterPosition &foundPosition,
  147.                                         FW_FindDirection direction=FW_kForwards) = 0;
  148.                                  
  149.     virtual FW_Boolean DoFindNonWhiteSpace(FW_CTextReader &reader,
  150.                                         FW_CharacterPosition &foundPosition,
  151.                                         FW_FindDirection direction=FW_kForwards) = 0;
  152.  
  153.     virtual FW_Boolean DoIsWhiteSpace(FW_Char character) = 0;
  154.                                  
  155.     virtual void DoConvertToUpper(FW_Char *chars, FW_CharacterCount length) = 0;
  156.     
  157.     virtual void DoConvertToLower(FW_Char *chars, FW_CharacterCount length) = 0;
  158.  
  159.     FW_Boolean fCaseSensitive;
  160.  
  161. private:
  162.  
  163.     static FW_CStringTool*& GetTool();
  164.     
  165. };
  166.  
  167. //----------------------------------------------------------------------------------------
  168. //    FW_CStringTool::CompareStrings
  169. //----------------------------------------------------------------------------------------
  170.  
  171. inline FW_StringCompareResult FW_CStringTool::CompareStrings(
  172.                                         FW_CTextReader &reader1,
  173.                                          FW_CTextReader &reader2)
  174. {
  175.     return DoCompareStrings(reader1, reader2);
  176. }
  177.  
  178. //----------------------------------------------------------------------------------------
  179. //    FW_CStringTool::FindCharacter
  180. //----------------------------------------------------------------------------------------
  181.  
  182. inline FW_Boolean FW_CStringTool::FindCharacter(FW_CTextReader& reader,
  183.                                                             FW_Char character,
  184.                                                             FW_CharacterPosition& foundPosition,
  185.                                                             FW_FindDirection direction)
  186. {
  187.     return DoFindCharacter(reader, character, foundPosition, direction);
  188. }
  189.  
  190.  
  191. //----------------------------------------------------------------------------------------
  192. //    FW_CStringTool::IsWhiteSpace
  193. //----------------------------------------------------------------------------------------
  194.  
  195. inline FW_Boolean FW_CStringTool::IsWhiteSpace(FW_Char character)
  196. {
  197.     return DoIsWhiteSpace(character);
  198. }
  199.                                                                  
  200. //----------------------------------------------------------------------------------------
  201. //    FW_CStringTool::FindWhiteSpace
  202. //----------------------------------------------------------------------------------------
  203.  
  204. inline FW_Boolean FW_CStringTool::FindWhiteSpace(
  205.                                         FW_CTextReader &reader,
  206.                                         FW_CharacterPosition &foundPosition,
  207.                                         FW_FindDirection direction)
  208. {
  209.     return DoFindWhiteSpace(reader, foundPosition, direction);
  210. }
  211.                                      
  212. //----------------------------------------------------------------------------------------
  213. //    FW_CStringTool::FindNonWhiteSpace
  214. //----------------------------------------------------------------------------------------
  215.  
  216. inline FW_Boolean FW_CStringTool::FindNonWhiteSpace(
  217.                                         FW_CTextReader &reader,
  218.                                         FW_CharacterPosition &foundPosition,
  219.                                         FW_FindDirection direction)
  220. {
  221.     return DoFindNonWhiteSpace(reader, foundPosition, direction);
  222. }
  223.                                      
  224. //========================================================================================
  225. //    CLASS FW_CMinimalStringTool
  226. //
  227. //        A minimalist, braindead string tool.  Operations are done without any knowledge
  228. //        of language, locale, character set, case sensitivity, etc.  This tool is provided
  229. //        for quick and dirty use where lack of such knowledge is not considered a problem.
  230. //        Real applications will need to use more sophisticated string tools, provided in
  231. //        other, higher level components.
  232. //========================================================================================
  233.  
  234. class FW_CMinimalStringTool : public FW_CStringTool
  235. {
  236. public:
  237.  
  238.     virtual ~FW_CMinimalStringTool();
  239.     FW_CMinimalStringTool(FW_Boolean caseSensitive=TRUE);
  240.  
  241. protected:
  242.     
  243.     virtual FW_StringCompareResult DoCompareStrings(FW_CTextReader &reader1,
  244.                                           FW_CTextReader &reader2);
  245.                                          
  246.     virtual FW_Boolean DoMatchPrefixString(FW_CTextReader &target,
  247.                                           FW_CTextReader &prefix);
  248.                                          
  249.     virtual FW_Boolean DoFindSubString(FW_CTextReader &searchStringReader,
  250.                                      FW_CTextReader &subStringReader,
  251.                                      FW_CharacterPosition &foundPosition);
  252.                                      
  253.     virtual FW_Boolean DoFindCharacter(FW_CTextReader &reader,
  254.                                     FW_Char character,
  255.                                     FW_CharacterPosition &foundPosition,
  256.                                     FW_FindDirection direction=FW_kForwards);
  257.                                  
  258.     virtual FW_Boolean DoFindWhiteSpace(FW_CTextReader &reader,
  259.                                         FW_CharacterPosition &foundPosition,
  260.                                         FW_FindDirection direction=FW_kForwards);
  261.                                  
  262.     virtual FW_Boolean DoFindNonWhiteSpace(FW_CTextReader &reader,
  263.                                         FW_CharacterPosition &foundPosition,
  264.                                         FW_FindDirection direction=FW_kForwards);
  265.  
  266.     virtual FW_Boolean DoIsWhiteSpace(FW_Char character);
  267.                                  
  268.     virtual void DoConvertToUpper(FW_Char *chars, FW_CharacterCount length);
  269.     
  270.     virtual void DoConvertToLower(FW_Char *chars, FW_CharacterCount length);
  271.  
  272. };
  273.  
  274. #endif
  275.